﻿using System;

namespace InDepth2Demo.Chapter2
{
    internal class CompareDemo
    {
        private static T Max<T>(T obj1, T obj2) where T : IComparable<T>
        {
            if (obj1.CompareTo(obj2) > 0)
            {
                return obj1;
            }

            return obj2;
        }

        public static void Call()
        {
            Console.WriteLine(Compare<int>.CompareGeneric(1, 2));
            Console.WriteLine(Compare<string>.CompareGeneric("string1", "string2"));
        }
    }

    class Compare<T> where T : IComparable
    {
        public static T CompareGeneric(T t1, T t2)
        {
            if (t1.CompareTo(t2) > 0)
            {
                return t1;
            }
            else
            {
                return t2;
            }
        }
    }
}
